package com.miyin.twpull.service.impl;

import com.miyin.twpull.service.TwUserPullService;
import com.twitter.clientlib.ApiException;
import com.twitter.clientlib.model.MultiUserLookupResponse;
import com.twitter.clientlib.model.SingleUserLookupResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 拉取用户数据
 */
@Service
public class TwUserPullServiceImpl implements TwUserPullService {

    @Autowired
    private TwCommonServiceImpl twCommonService;

    /**
     * 获取用户信息，根据用户名。
     *
     * @param username 用户名列表，最多可以指定100个用户名。
     */
    @Override
    public void getUserInfoByUsernames(String... username) {
        // TODO 参数提出来
        Set<String> expansions = new HashSet<>(Arrays.asList());
        Set<String> tweetFields = new HashSet<>(Arrays.asList());
        Set<String> userFields = new HashSet<>(Arrays.asList(
                "created_at",
                "description",
                "entities,id",
                "location,name",
                "pinned_tweet_id",
                "profile_image_url",
                "protected",
                "public_metrics",
                "url",
                "username",
                "verified",
                "withheld"));

        List<String> usernames = Arrays.asList(username);

        try {
            MultiUserLookupResponse result = twCommonService.getTwitterApiByBearerToken().users().findUsersByUsername(usernames, expansions, tweetFields, userFields);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling UsersApi#findUserByUsername");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }

}
